unit Class_Unit;


interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TDW=class(TUniEngine)
  private
    FDWBML    : string;
    FDWJS     : Integer;
    FDWBM     : string;
    FDWMC     : string;
    FDWJC     : string;
    FDWZGBM   : string;
    FDWXZ     : string;
    FDWDWLX   : string;
    FDWSJM    : string;
    FDWDZ     : string;                                     
    FDWLXDH   : string;
    FDWFZR    : string;
    FDWCWFZR  : string;
    FDWGNKM   : TMemoryStream;
    FDWJJKM   : TMemoryStream;
    FDWZTBM   : Integer;
    FDWZTMC   : string;
    FDWKMBML  : string;
    FDWSYTAG  : Integer;
    FDWSTDTAG : Integer;
    FDWTAG    : Integer;
    FDWFIELD1 : string;
    FDWFIELD2 : string;
    FDWFIELD3 : string;
    FDWFIELD4 : string;
    FDWFIELD5 : string;
    FDWFIELD6 : Integer;
    FDWFIELD7 : Integer;
    FDWFIELD8 : Integer;
    FDWFIELD9 : Integer;
    FDWYWKS   : string;
    FDWGZFF   : Integer;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property DWBML    : string read FDWBML     write FDWBML;
    property DWJS     : Integer read FDWJS      write FDWJS;
    property DWBM     : string read FDWBM      write FDWBM;
    property DWMC     : string read FDWMC      write FDWMC;
    property DWJC     : string read FDWJC      write FDWJC;
    property DWZGBM   : string read FDWZGBM    write FDWZGBM;
    property DWXZ     : string read FDWXZ      write FDWXZ;
    property DWDWLX   : string read FDWDWLX    write FDWDWLX;
    property DWSJM    : string read FDWSJM     write FDWSJM;
    property DWDZ     : string read FDWDZ      write FDWDZ;
    property DWLXDH   : string read FDWLXDH    write FDWLXDH;
    property DWFZR    : string read FDWFZR     write FDWFZR;
    property DWCWFZR  : string read FDWCWFZR   write FDWCWFZR;
    property DWGNKM   : TMemoryStream read FDWGNKM    write FDWGNKM;
    property DWJJKM   : TMemoryStream read FDWJJKM    write FDWJJKM;
    property DWZTBM   : Integer read FDWZTBM    write FDWZTBM;
    property DWZTMC   : string read FDWZTMC    write FDWZTMC;
    property DWKMBML  : string read FDWKMBML   write FDWKMBML;
    property DWSYTAG  : Integer read FDWSYTAG   write FDWSYTAG;
    property DWSTDTAG : Integer read FDWSTDTAG  write FDWSTDTAG;
    property DWTAG    : Integer read FDWTAG     write FDWTAG;
    property DWFIELD1 : string read FDWFIELD1  write FDWFIELD1;
    property DWFIELD2 : string read FDWFIELD2  write FDWFIELD2;
    property DWFIELD3 : string read FDWFIELD3  write FDWFIELD3;
    property DWFIELD4 : string read FDWFIELD4  write FDWFIELD4;
    property DWFIELD5 : string read FDWFIELD5  write FDWFIELD5;
    property DWFIELD6 : Integer read FDWFIELD6  write FDWFIELD6;
    property DWFIELD7 : Integer read FDWFIELD7  write FDWFIELD7;
    property DWFIELD8 : Integer read FDWFIELD8  write FDWFIELD8;
    property DWFIELD9 : Integer read FDWFIELD9  write FDWFIELD9;
    property DWYWKS   : string read FDWYWKS    write FDWYWKS;
    property DWGZFF   : Integer read FDWGZFF    write FDWGZFF;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(ADW:TDW):TDW;overload;        
    class procedure CopyIt(ADW:TDW;var Result:TDW);overload;       
  end;

implementation

{ TDW }
procedure TDW.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('DW_BML').Value := DWBML;
        ParamByName('DW_JS').Value := DWJS;
        ParamByName('DW_BM').Value := DWBM;
        ParamByName('DW_MC').Value := DWMC;
        ParamByName('DW_JC').Value := DWJC;
        ParamByName('DW_ZGBM').Value := DWZGBM;
        ParamByName('DW_XZ').Value := DWXZ;
        ParamByName('DW_DWLX').Value := DWDWLX;
        ParamByName('DW_SJM').Value := DWSJM;
        ParamByName('DW_DZ').Value := DWDZ;
        ParamByName('DW_LXDH').Value := DWLXDH;
        ParamByName('DW_FZR').Value := DWFZR;
        ParamByName('DW_CWFZR').Value := DWCWFZR;

//        ParamByName('DW_GNKM').Value := DWGNKM;
//        ParamByName('DW_JJKM').Value := DWJJKM;

        ParamByName('DW_GNKM').LoadFromStream(DWGNKM,ftBlob);
        ParamByName('DW_JJKM').LoadFromStream(DWJJKM,ftBlob);        


        ParamByName('DW_ZT_BM').Value := DWZTBM;
        ParamByName('DW_ZT_MC').Value := DWZTMC;
        ParamByName('DW_KMBML').Value := DWKMBML;
        ParamByName('DW_SYTAG').Value := DWSYTAG;
        ParamByName('DW_STDTAG').Value := DWSTDTAG;
        ParamByName('DW_TAG').Value := DWTAG;
        ParamByName('DW_FIELD1').Value := DWFIELD1;
        ParamByName('DW_FIELD2').Value := DWFIELD2;
        ParamByName('DW_FIELD3').Value := DWFIELD3;
        ParamByName('DW_FIELD4').Value := DWFIELD4;
        ParamByName('DW_FIELD5').Value := DWFIELD5;
        ParamByName('DW_FIELD6').Value := DWFIELD6;
        ParamByName('DW_FIELD7').Value := DWFIELD7;
        ParamByName('DW_FIELD8').Value := DWFIELD8;
        ParamByName('DW_FIELD9').Value := DWFIELD9;
        ParamByName('DW_YWKS').Value := DWYWKS;
        ParamByName('DW_GZFF').Value := DWGZFF; 
      end;
      otEdit:
      begin
        ParamByName('DW_BML').Value := DWBML;
        ParamByName('DW_JS').Value := DWJS;
        ParamByName('DW_BM').Value := DWBM;
        ParamByName('DW_MC').Value := DWMC;
        ParamByName('DW_JC').Value := DWJC;
        ParamByName('DW_ZGBM').Value := DWZGBM;
        ParamByName('DW_XZ').Value := DWXZ;
        ParamByName('DW_DWLX').Value := DWDWLX;
        ParamByName('DW_SJM').Value := DWSJM;
        ParamByName('DW_DZ').Value := DWDZ;
        ParamByName('DW_LXDH').Value := DWLXDH;
        ParamByName('DW_FZR').Value := DWFZR;
        ParamByName('DW_CWFZR').Value := DWCWFZR;
        
//        ParamByName('DW_GNKM').Value := DWGNKM;
//        ParamByName('DW_JJKM').Value := DWJJKM;

        ParamByName('DW_GNKM').LoadFromStream(DWGNKM,ftBlob);
        ParamByName('DW_JJKM').LoadFromStream(DWJJKM,ftBlob);

        ParamByName('DW_ZT_BM').Value := DWZTBM;
        ParamByName('DW_ZT_MC').Value := DWZTMC;
        ParamByName('DW_KMBML').Value := DWKMBML;
        ParamByName('DW_SYTAG').Value := DWSYTAG;
        ParamByName('DW_STDTAG').Value := DWSTDTAG;
        ParamByName('DW_TAG').Value := DWTAG;
        ParamByName('DW_FIELD1').Value := DWFIELD1;
        ParamByName('DW_FIELD2').Value := DWFIELD2;
        ParamByName('DW_FIELD3').Value := DWFIELD3;
        ParamByName('DW_FIELD4').Value := DWFIELD4;
        ParamByName('DW_FIELD5').Value := DWFIELD5;
        ParamByName('DW_FIELD6').Value := DWFIELD6;
        ParamByName('DW_FIELD7').Value := DWFIELD7;
        ParamByName('DW_FIELD8').Value := DWFIELD8;
        ParamByName('DW_FIELD9').Value := DWFIELD9;
        ParamByName('DW_YWKS').Value := DWYWKS;
        ParamByName('DW_GZFF').Value := DWGZFF; 
      end;  
      otDelt:
      begin
        ParamByName('DW_BML').Value := DWBML;
 
      end;  
    end;
  end;
end;

function TDW.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_DW',['DW_BML',DWBML],AUniConnection);
end;

function TDW.GetNextIdex: Integer;
begin

end;

function TDW.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TDW.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_DW WHERE   DW_BML=:DW_BML';
end;

function TDW.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_DW'
         +'    ( DW_BML, DW_JS, DW_BM, DW_MC, DW_JC, DW_ZGBM, DW_XZ'
         +'    , DW_DWLX, DW_SJM, DW_DZ, DW_LXDH, DW_FZR, DW_CWFZR'
         +'    , DW_GNKM, DW_JJKM, DW_ZT_BM, DW_ZT_MC, DW_KMBML, DW_SYTAG'
         +'    , DW_STDTAG, DW_TAG, DW_FIELD1, DW_FIELD2, DW_FIELD3'
         +'    , DW_FIELD4, DW_FIELD5, DW_FIELD6, DW_FIELD7, DW_FIELD8'
         +'    , DW_FIELD9, DW_YWKS, DW_GZFF)'
         +'    VALUES'
         +'    (:DW_BML,:DW_JS,:DW_BM,:DW_MC,:DW_JC,:DW_ZGBM,:DW_XZ'
         +'    ,:DW_DWLX,:DW_SJM,:DW_DZ,:DW_LXDH,:DW_FZR,:DW_CWFZR'
         +'    ,:DW_GNKM,:DW_JJKM,:DW_ZT_BM,:DW_ZT_MC,:DW_KMBML,:DW_SYTAG'
         +'    ,:DW_STDTAG,:DW_TAG,:DW_FIELD1,:DW_FIELD2,:DW_FIELD3'
         +'    ,:DW_FIELD4,:DW_FIELD5,:DW_FIELD6,:DW_FIELD7,:DW_FIELD8'
         +'    ,:DW_FIELD9,:DW_YWKS,:DW_GZFF)';
end;

function TDW.GetStrsIndex: string;
begin
  Result:=Format('%S',[DWBML]);
end;

function TDW.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_DW SET'
         +'    DW_JS=:DW_JS,'
         +'    DW_BM=:DW_BM,'
         +'    DW_MC=:DW_MC,'
         +'    DW_JC=:DW_JC,'
         +'    DW_ZGBM=:DW_ZGBM,'
         +'    DW_XZ=:DW_XZ,'
         +'    DW_DWLX=:DW_DWLX,'
         +'    DW_SJM=:DW_SJM,'
         +'    DW_DZ=:DW_DZ,'
         +'    DW_LXDH=:DW_LXDH,'
         +'    DW_FZR=:DW_FZR,'
         +'    DW_CWFZR=:DW_CWFZR,'
         +'    DW_GNKM=:DW_GNKM,'
         +'    DW_JJKM=:DW_JJKM,'
         +'    DW_ZT_BM=:DW_ZT_BM,'
         +'    DW_ZT_MC=:DW_ZT_MC,'
         +'    DW_KMBML=:DW_KMBML,'
         +'    DW_SYTAG=:DW_SYTAG,'
         +'    DW_STDTAG=:DW_STDTAG,'
         +'    DW_TAG=:DW_TAG,'
         +'    DW_FIELD1=:DW_FIELD1,'
         +'    DW_FIELD2=:DW_FIELD2,'
         +'    DW_FIELD3=:DW_FIELD3,'
         +'    DW_FIELD4=:DW_FIELD4,'
         +'    DW_FIELD5=:DW_FIELD5,'
         +'    DW_FIELD6=:DW_FIELD6,'
         +'    DW_FIELD7=:DW_FIELD7,'
         +'    DW_FIELD8=:DW_FIELD8,'
         +'    DW_FIELD9=:DW_FIELD9,'
         +'    DW_YWKS=:DW_YWKS,'
         +'    DW_GZFF=:DW_GZFF'
         +'    WHERE DW_BML=:DW_BML';
end;

constructor TDW.Create;
begin
  FDWGNKM:=TMemoryStream.Create;
  FDWJJKM:=TMemoryStream.Create;
end;

destructor TDW.Destroy;
begin
  if FDWJJKM<>nil then FreeAndNil(FDWJJKM);
  if FDWGNKM<>nil then FreeAndNil(FDWGNKM);
  inherited;
end;

class function TDW.ReadDS(AUniQuery: TUniQuery): TUniEngine;
var
  I:Integer;
  Field:TField;
begin
  Result:=TDW.Create;

  with TDW(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      if Field.FieldName='DW_BML' then
      begin
        DWBML    :=Field.AsString;
      end else
      if Field.FieldName='DW_JS' then
      begin
        DWJS     :=Field.AsInteger;
      end else
      if Field.FieldName='DW_BM' then
      begin
        DWBM     :=Field.AsString;
      end else
      if Field.FieldName='DW_MC' then
      begin
        DWMC     :=Field.AsString;
      end else
      if Field.FieldName='DW_JC' then
      begin
        DWJC     :=Field.AsString;
      end else
      if Field.FieldName='DW_ZGBM' then
      begin
        DWZGBM   :=Field.AsString;
      end else
      if Field.FieldName='DW_XZ' then
      begin
        DWXZ     :=Field.AsString;
      end else
      if Field.FieldName='DW_DWLX' then
      begin
        DWDWLX   :=Field.AsString;
      end else
      if Field.FieldName='DW_SJM' then
      begin
        DWSJM    :=Field.AsString;
      end else
      if Field.FieldName='DW_DZ' then
      begin
        DWDZ     :=Field.AsString;
      end else
      if Field.FieldName='DW_LXDH' then
      begin
        DWLXDH   :=Field.AsString;
      end else
      if Field.FieldName='DW_FZR' then
      begin
        DWFZR    :=Field.AsString;
      end else
      if Field.FieldName='DW_CWFZR' then
      begin
        DWCWFZR  :=Field.AsString;
      end else
      if Field.FieldName='DW_GNKM' then
      begin
        //DWGNKM   :=Field.AsString;
        TBlobField(Field).SaveToStream(DWGNKM);
      end else
      if Field.FieldName='DW_JJKM' then
      begin
        //DWJJKM   :=Field.AsString;
        TBlobField(Field).SaveToStream(DWJJKM);        
      end else
      if Field.FieldName='DW_ZT_BM' then
      begin
        DWZTBM   :=Field.AsInteger;
      end else
      if Field.FieldName='DW_ZT_MC' then
      begin
        DWZTMC   :=Field.AsString;
      end else
      if Field.FieldName='DW_KMBML' then
      begin
        DWKMBML  :=Field.AsString;
      end else
      if Field.FieldName='DW_SYTAG' then
      begin
        DWSYTAG  :=Field.AsInteger;
      end else
      if Field.FieldName='DW_STDTAG' then
      begin
        DWSTDTAG :=Field.AsInteger;
      end else
      if Field.FieldName='DW_TAG' then
      begin
        DWTAG    :=Field.AsInteger;
      end else
      if Field.FieldName='DW_FIELD1' then
      begin
        DWFIELD1 :=Field.AsString;
      end else
      if Field.FieldName='DW_FIELD2' then
      begin
        DWFIELD2 :=Field.AsString;
      end else
      if Field.FieldName='DW_FIELD3' then
      begin
        DWFIELD3 :=Field.AsString;
      end else
      if Field.FieldName='DW_FIELD4' then
      begin
        DWFIELD4 :=Field.AsString;
      end else
      if Field.FieldName='DW_FIELD5' then
      begin
        DWFIELD5 :=Field.AsString;
      end else
      if Field.FieldName='DW_FIELD6' then
      begin
        DWFIELD6 :=Field.AsInteger;
      end else
      if Field.FieldName='DW_FIELD7' then
      begin
        DWFIELD7 :=Field.AsInteger;
      end else
      if Field.FieldName='DW_FIELD8' then
      begin
        DWFIELD8 :=Field.AsInteger;
      end else
      if Field.FieldName='DW_FIELD9' then
      begin
        DWFIELD9 :=Field.AsInteger;
      end else
      if Field.FieldName='DW_YWKS' then
      begin
        DWYWKS   :=Field.AsString;
      end else
      if Field.FieldName='DW_GZFF' then
      begin
        DWGZFF   :=Field.AsInteger;
      end;
    end
  end;  
end;

class procedure TDW.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
begin
  if Result=nil then Exit;

  with TDW(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      if Field.FieldName='DW_BML' then
      begin
        DWBML    :=Field.AsString;
      end else
      if Field.FieldName='DW_JS' then
      begin
        DWJS     :=Field.AsInteger;
      end else
      if Field.FieldName='DW_BM' then
      begin
        DWBM     :=Field.AsString;
      end else
      if Field.FieldName='DW_MC' then
      begin
        DWMC     :=Field.AsString;
      end else
      if Field.FieldName='DW_JC' then
      begin
        DWJC     :=Field.AsString;
      end else
      if Field.FieldName='DW_ZGBM' then
      begin
        DWZGBM   :=Field.AsString;
      end else
      if Field.FieldName='DW_XZ' then
      begin
        DWXZ     :=Field.AsString;
      end else
      if Field.FieldName='DW_DWLX' then
      begin
        DWDWLX   :=Field.AsString;
      end else
      if Field.FieldName='DW_SJM' then
      begin
        DWSJM    :=Field.AsString;
      end else
      if Field.FieldName='DW_DZ' then
      begin
        DWDZ     :=Field.AsString;
      end else
      if Field.FieldName='DW_LXDH' then
      begin
        DWLXDH   :=Field.AsString;
      end else
      if Field.FieldName='DW_FZR' then
      begin
        DWFZR    :=Field.AsString;
      end else
      if Field.FieldName='DW_CWFZR' then
      begin
        DWCWFZR  :=Field.AsString;
      end else
      if Field.FieldName='DW_GNKM' then
      begin
        TBlobField(Field).SaveToStream(DWGNKM);
      end else
      if Field.FieldName='DW_JJKM' then
      begin
        TBlobField(Field).SaveToStream(DWJJKM);
      end else
      if Field.FieldName='DW_ZT_BM' then
      begin
        DWZTBM   :=Field.AsInteger;
      end else
      if Field.FieldName='DW_ZT_MC' then
      begin
        DWZTMC   :=Field.AsString;
      end else
      if Field.FieldName='DW_KMBML' then
      begin
        DWKMBML  :=Field.AsString;
      end else
      if Field.FieldName='DW_SYTAG' then
      begin
        DWSYTAG  :=Field.AsInteger;
      end else
      if Field.FieldName='DW_STDTAG' then
      begin
        DWSTDTAG :=Field.AsInteger;
      end else
      if Field.FieldName='DW_TAG' then
      begin
        DWTAG    :=Field.AsInteger;
      end else
      if Field.FieldName='DW_FIELD1' then
      begin
        DWFIELD1 :=Field.AsString;
      end else
      if Field.FieldName='DW_FIELD2' then
      begin
        DWFIELD2 :=Field.AsString;
      end else
      if Field.FieldName='DW_FIELD3' then
      begin
        DWFIELD3 :=Field.AsString;
      end else
      if Field.FieldName='DW_FIELD4' then
      begin
        DWFIELD4 :=Field.AsString;
      end else
      if Field.FieldName='DW_FIELD5' then
      begin
        DWFIELD5 :=Field.AsString;
      end else
      if Field.FieldName='DW_FIELD6' then
      begin
        DWFIELD6 :=Field.AsInteger;
      end else
      if Field.FieldName='DW_FIELD7' then
      begin
        DWFIELD7 :=Field.AsInteger;
      end else
      if Field.FieldName='DW_FIELD8' then
      begin
        DWFIELD8 :=Field.AsInteger;
      end else
      if Field.FieldName='DW_FIELD9' then
      begin
        DWFIELD9 :=Field.AsInteger;
      end else
      if Field.FieldName='DW_YWKS' then
      begin
        DWYWKS   :=Field.AsString;
      end else
      if Field.FieldName='DW_GZFF' then
      begin
        DWGZFF   :=Field.AsInteger;
      end;
    end
  end;  
end;

class function  TDW.CopyIt(ADW: TDW): TDW;
begin
  Result:=TDW.Create;
  TDW.CopyIt(ADW,Result)
end;

class procedure TDW.CopyIt(ADW:TDW;var Result:TDW);
begin
  if Result=nil then Exit;
  Result.DWBML    :=ADW.DWBML;
  Result.DWJS     :=ADW.DWJS;
  Result.DWBM     :=ADW.DWBM;
  Result.DWMC     :=ADW.DWMC;
  Result.DWJC     :=ADW.DWJC;
  Result.DWZGBM   :=ADW.DWZGBM;
  Result.DWXZ     :=ADW.DWXZ;
  Result.DWDWLX   :=ADW.DWDWLX;
  Result.DWSJM    :=ADW.DWSJM;
  Result.DWDZ     :=ADW.DWDZ;
  Result.DWLXDH   :=ADW.DWLXDH;
  Result.DWFZR    :=ADW.DWFZR;
  Result.DWCWFZR  :=ADW.DWCWFZR;
  Result.DWGNKM   :=ADW.DWGNKM;
  Result.DWJJKM   :=ADW.DWJJKM;
  Result.DWZTBM   :=ADW.DWZTBM;
  Result.DWZTMC   :=ADW.DWZTMC;
  Result.DWKMBML  :=ADW.DWKMBML;
  Result.DWSYTAG  :=ADW.DWSYTAG;
  Result.DWSTDTAG :=ADW.DWSTDTAG;
  Result.DWTAG    :=ADW.DWTAG;
  Result.DWFIELD1 :=ADW.DWFIELD1;
  Result.DWFIELD2 :=ADW.DWFIELD2;
  Result.DWFIELD3 :=ADW.DWFIELD3;
  Result.DWFIELD4 :=ADW.DWFIELD4;
  Result.DWFIELD5 :=ADW.DWFIELD5;
  Result.DWFIELD6 :=ADW.DWFIELD6;
  Result.DWFIELD7 :=ADW.DWFIELD7;
  Result.DWFIELD8 :=ADW.DWFIELD8;
  Result.DWFIELD9 :=ADW.DWFIELD9;
  Result.DWYWKS   :=ADW.DWYWKS;
  Result.DWGZFF   :=ADW.DWGZFF;
end;

end.

